package lambdaDemo;

import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.function.Consumer;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-10-10
 * Time: 14:47
 */


//无返回值一个参数
@FunctionalInterface
interface func2{
    void test(int a);
}

//无返回值多个参数
@FunctionalInterface
interface func3{
    void test(int a,int b);
}

//有返回值无参数
@FunctionalInterface
interface func4{
    int test();
}

//有返回值一个参数
@FunctionalInterface
interface func5{
    int test(int a);
}

//有返回值多个参数
@FunctionalInterface
interface func6{
    int test(int a,int b);
}

//无返回值无参数
@FunctionalInterface
interface func1{
    void test();
}



public class Test {
    public static void main(String[] args) {
        List<String> list = new LinkedList<>();
        list.add("haksdkd");
        list.add("skjdklkd");
        list.add("dfjdjdkj");
        list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });

        System.out.println("============");
        list.forEach(s -> System.out.println(s));
    }
    public static void main7(String[] args) {
        PriorityQueue<Integer> queue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1.compareTo(o2);
            }
        });

        PriorityQueue<Integer> queue1 = new PriorityQueue<>((o1,o2) -> o1.compareTo(o2));
    }
    public static void main6(String[] args) {
        func6 f = new func6() {
            @Override
            public int test(int a, int b) {
                return a + b;
            }
        };
        System.out.println(f.test(20, 30));
        System.out.println("===========");
        func6 f1 = (a,b)-> {return a + b;};
        System.out.println(f1.test(20,40));
    }
    public static void main5(String[] args) {
        func5 f = new func5() {
            @Override
            public int test(int a) {
                return a + 3;
            }
        };
        System.out.println(f.test(9));
        System.out.println("=======");
        func5 f1 = a-> a + 3;
        System.out.println(f1.test(20));
    }
    public static void main4(String[] args) {
        func4 f = new func4(){
            @Override
            public int test() {
                return 10;
            }
        };
        System.out.println(f.test());
        System.out.println("=========");
        func4 f1 = () -> {return 10;};
        System.out.println(f1.test());
    }
    public static void main3(String[] args) {
        func3 f = new func3(){
            @Override
            public void test(int a,int b){
                System.out.println(a + b);
            }
        };
        f.test(2,3);
        System.out.println("==========");
//        func3 f1 = (int a,int b) -> {
//            System.out.println(a + b);
//        };
        func3 f1 = (a,b)-> System.out.println(a + b);
        f1.test(2,3);
    }
    public static void main2(String[] args) {
        func2 f = new func2(){
            @Override
            public void test(int a){
                System.out.println(a + 3);
            }
        };
        f.test(2);
        System.out.println("===========");
//        func2 f1 = (int a) -> {
//            System.out.println(a + 9);
//        };
        func2 f1 = a -> System.out.println(a + 90);
        f1.test(2);
    }
    public static void main1(String[] args) {
        func1 f = new func1(){
            @Override
            public void test(){
                System.out.println("hello test");
            }
        };
        f.test();
        System.out.println("==========");
//        func1 f1 = () -> {
//            System.out.println("hello test");
//        };
        func1 f1 = () -> System.out.println("hello test");
        f1.test();
    }
}
